<?php


namespace app\enterprise\service;


use think\Request;

class Coupon
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }

    /**
     * 获取全部优惠卷
     * @param $token
     * @return |null
     */
    public function getCouponList($token){
        $url = $this->url."/enterprise/coupon";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }


    /*** 返回小程序码
     * @param $token
     * @param $c_id
     * @param $page
     * @return null
     *
     */
    public function getQrCode($token,$c_id,$page){
        $url = $this->url."/enterprise/coupon/qrcode";
        $params = [
          'c_id'=>$c_id,
          'page'=>$page
        ];
        $result  = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }


    /***获客详情
     * @param $token
     * @param $id
     * @return null
     *
     */
    public function getCustomer($token,$id){
        $url = $this->url."/enterprise/coupon/user/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }

    }

    /*** 创建优惠券
     * @return null
     *
     */
    public function AddCoupon($token){
        $input = input();
        $url = $this->url."/enterprise/coupon/add";
        $result = curl_post($url,$token,$input);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }

    }


    /*** 下架优惠券
     * @param $token
     * @return null
     *
     */
    public function ChangeStatus($token){
        $data = input();
        $url = $this->url."/enterprise/coupon/up";
        $result = curl_post($url,$token,$data);
        $res = json_decode($result);
        if ($res->code == 200){
            return $res->content;
        }else{
            return null;
        }
    }


    /*** 教练优惠券
     * @param $token
     * @return null
     *
     */
    public function UserCouponList($token){
        $url = $this->url."/enterprise/coupon/list";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }


    /***
     * 优惠券详情
     * @param $id
     * @param $token
     * @return null
     */
    public function CouponDetails($id,$token){
        $url = $this->url."/enterprise/coupon/detail/".$id;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code == 200){
            return $data->content;
        }else{
            return null;
        }
    }
}